<template>
	<view class="pet_sell">
		<Navbar>出售中心</Navbar>
		<view class="tabs">
			<view class="item" :class="active==1?'active':''" @click="changeActive(1)">
				售卖中
			</view>
			<view class="item" :class="active==2?'active':''" @click="changeActive(2)">
				已出售
			</view>
		</view>
		<view class="content">
			<view class="title">我的出售</view>
			<scroll-view scroll-y class="scroll_view">
				<view class="item" v-for="item in list">
					<view class="info">
						<view class="cover" @click="look(item)">
							<image :src="item.product_cover"></image>
						</view>
						<view class="info_view">
							<view class="name">{{item.product_name}}</view>
							<view class="progress_box">
								<view class="key">生命值</view>
								<view class="progress_view">
									<view class="progress" :style="{width:item.health>100?100:item.health+'%'}"></view>
									<view class="text">{{item.health}}/100</view>
								</view>
							</view>
							<view class="price">￥{{item.price}}</view>
						</view>
					</view>
					<view class="btn" v-if="active==1">
						<view @click="submit(item)">取消出售</view>
					</view>
				</view>
				<u-loadmore :status="loadmore_status" :color="$store.state.loadmoreColor"
					:lineColor="$store.state.loadmoreColor" line @loadmore="loadmore" />
			</scroll-view>
		</view>
		<u-popup :show="popup_show" bgColor="transparent" mode="center" @close="close">
			<PetDetaTwo :id="item.id" :type="active" @close="close" @cancel="popup=2" v-if="popup==1" />
			<PetCancel :item="item" @close="close" @success="success" v-else />
		</u-popup>
	</view>
</template>

<script>
	import {
		skillSell
	} from '@/request/api.js';

	import PetDetaTwo from '@/components/home/PetDetaTwo.vue';
	import PetCancel from '@/components/home/PetCancel.vue';
	export default {
		components: {
			PetDetaTwo,
			PetCancel
		},
		data() {
			return {
				active: 1,
				list: [],

				item: {},
				popup_show: false,
				popup: 1
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			async getList() {
				let {
					list
				} = await skillSell({
					page: this.page,
					limit: this.limit,
					from: this.active
				});
				// this.list = list.data;
				this.last_page = list.last_page;
				list = list.data;
				this.list = this.page == 1 ? list : [...this.list, ...list];
				this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
			},
			changeActive(index) {
				this.active = index;
				this.getList();
			},
			look(item) {
				this.item = item;
				this.open(1);
			},
			submit(item) {
				this.item = item;
				this.open(2);
			},
			open(index) {
				this.popup = index;
				this.popup_show = true;
			},
			close() {
				this.popup_show = false;
			},
			success() {
				this.popup_show = false;
				this.page = 1;
				this.list = [];
				this.getList();
			}
		}
	}
</script>

<style scoped lang="scss">
	.pet_sell {
		height: 100vh;
		background: #29170D;
		overflow: hidden;

		.tabs {
			width: 710rpx;
			height: 100rpx;
			margin: 0 auto;
			padding: 0 10rpx;
			box-sizing: border-box;
			background-color: rgba(31, 11, 5, 0.6);
			display: flex;
			justify-content: center;
			align-items: center;

			.item {
				width: 180rpx;
				height: 70rpx;
				line-height: 70rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 36rpx;
				font-weight: 400;
				font-family: LiSu;
				margin: 0 60rpx;

				&.active {
					color: #494338;
					background: url(#{$baseImageUrl}/common/active.png) no-repeat;
					background-size: 100% 100%;
				}
			}
		}

		.content {
			height: calc(100vh - #{$navbarHeight} - 100rpx - 20rpx);
			padding: 210rpx 25rpx 25rpx;
			box-sizing: border-box;
			background: url(#{$baseImageUrl}/bg/bg3.png) no-repeat;
			background-size: 100% 100%;
			position: relative;

			.title {
				width: 100%;
				height: 210rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 36rpx;
				font-weight: 400;
				font-family: LiSu;
				padding-bottom: 52rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: center;
				align-items: flex-end;
				position: absolute;
				left: 0;
				top: 0;
			}
		}

		.scroll_view {
			height: 100%;

			.item {
				width: 100%;
				// height: 344rpx;
				margin-bottom: 20rpx;
				padding: 36rpx 38rpx;
				box-sizing: border-box;
				background: url(#{$baseImageUrl}/bg/690_344.png) no-repeat;
				background-size: 100% 100%;

				.info {
					display: flex;

					.cover {
						width: 200rpx;
						height: 200rpx;
						background: url(#{$baseImageUrl}/bg/avatar.png) no-repeat;
						background-size: 100% 100%;
						display: flex;
						justify-content: center;
						align-items: flex-end;

						image {
							width: 178rpx;
							height: 178rpx;
						}
					}

					.info_view {
						flex: 1;
						padding: 16rpx 25rpx;
						box-sizing: border-box;
						overflow: hidden;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.name {
							color: #494338;
							font-size: 50rpx;
							font-weight: 400;
							font-family: LiSu;
						}

						.progress_box {
							display: flex;
							align-items: center;

							.key {
								color: #494338;
								font-size: 28rpx;
								font-weight: 400;
								font-family: SimSun;
								padding-right: 16rpx;
								box-sizing: border-box;
							}

							.progress_view {
								flex: 1;
								height: 25rpx;
								background: #B4A88E;
								box-shadow: 0px 0px 4px 0px rgba(110, 93, 72, 0.67);
								position: relative;

								.text {
									width: 100%;
									height: 25rpx;
									line-height: 25rpx;
									text-align: center;
									color: #494338;
									font-size: 24rpx;
									font-weight: 400;
									font-family: SimSun;
									box-sizing: border-box;
									position: absolute;
									left: 0;
									top: 0;
									z-index: 2;
								}

								.progress {
									// width: 30%;
									height: 100%;
									background: linear-gradient(90deg, #E68B30, #FAD44C);
								}
							}
						}

						.price {
							color: #494338;
							font-size: 28rpx;
							font-weight: 400;
							font-family: SimSun;
						}
					}
				}

				.btn {
					display: flex;
					justify-content: flex-end;

					view {
						width: 204rpx;
						height: 74rpx;
						line-height: 74rpx;
						text-align: center;
						color: #FFFFFF;
						font-size: 30rpx;
						font-family: SimSun;
						font-weight: 400;
						background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
						background-size: 100% 100%;
					}
				}
			}
		}
	}
</style>